package com.sctvcloud.linshui.ui.adapter.holder;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.ruihang.generalibrary.ui.widget.CustomFontTextView;
import com.ruihang.generalibrary.ui.widget.CustomLinearLayout;
import com.ruihang.generalibrary.utils.ListUtils;
import com.sctvcloud.linshui.R;
import com.sctvcloud.linshui.beans.HomeListItem;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class FarmersEntrysHolder extends BaseAbsHolder<HomeListItem> {

    @BindView(R.id.first_le)
    protected LinearLayout first_le;
    @BindView(R.id.second_le)
    protected LinearLayout second_le;


    @BindView(R.id.entry_1_layout)
    protected LinearLayout entry_1_layout;
    @BindView(R.id.entry_2_layout)
    protected LinearLayout entry_2_layout;
    @BindView(R.id.entry_3_layout)
    protected LinearLayout entry_3_layout;
    @BindView(R.id.entry_4_layout)
    protected LinearLayout entry_4_layout;
    @BindView(R.id.entry_5_layout)
    protected LinearLayout entry_5_layout;
    @BindView(R.id.entry_6_layout)
    protected LinearLayout entry_6_layout;

    @BindView(R.id.entry_1)
    protected CustomFontTextView entry_1;
    @BindView(R.id.entry_2)
    protected CustomFontTextView entry_2;
    @BindView(R.id.entry_3)
    protected CustomFontTextView entry_3;
    @BindView(R.id.entry_4)
    protected CustomFontTextView entry_4;
    @BindView(R.id.entry_5)
    protected CustomFontTextView entry_5;
    @BindView(R.id.entry_6)
    protected CustomFontTextView entry_6;

    private HomeListItem homeListItem;
    private OnFarmersEntrysClickListener farmersEntryClickListener;

    public FarmersEntrysHolder(Context context, View itemView, OnFarmersEntrysClickListener listener) {
        super(context, itemView);
        this.farmersEntryClickListener = listener;
    }

    @Override
    public void setData(HomeListItem item) {
        homeListItem = item;
        String title1,title2,title3,title4,title5,title6;
        if(null!=item&&ListUtils.isListValued(item.getChannelList())){
            if(item.getChannelList().size()==1){
                first_le.setVisibility(View.VISIBLE);
                second_le.setVisibility(View.GONE);
                entry_1_layout.setVisibility(View.VISIBLE);
            }else if(item.getChannelList().size()==2){
                first_le.setVisibility(View.VISIBLE);
                second_le.setVisibility(View.GONE);
                entry_1_layout.setVisibility(View.VISIBLE);
                entry_2_layout.setVisibility(View.VISIBLE);
            }else if(item.getChannelList().size()==3){
                first_le.setVisibility(View.VISIBLE);
                second_le.setVisibility(View.GONE);
                entry_1_layout.setVisibility(View.VISIBLE);
                entry_2_layout.setVisibility(View.VISIBLE);
                entry_3_layout.setVisibility(View.VISIBLE);
            }else if(item.getChannelList().size()==4){
                first_le.setVisibility(View.VISIBLE);
                second_le.setVisibility(View.VISIBLE);
                entry_1_layout.setVisibility(View.VISIBLE);
                entry_2_layout.setVisibility(View.VISIBLE);
                entry_3_layout.setVisibility(View.VISIBLE);
                entry_4_layout.setVisibility(View.VISIBLE);
            }else if(item.getChannelList().size()==5){
                first_le.setVisibility(View.VISIBLE);
                second_le.setVisibility(View.VISIBLE);
                entry_1_layout.setVisibility(View.VISIBLE);
                entry_2_layout.setVisibility(View.VISIBLE);
                entry_3_layout.setVisibility(View.VISIBLE);
                entry_4_layout.setVisibility(View.VISIBLE);
                entry_5_layout.setVisibility(View.VISIBLE);
            }else if(item.getChannelList().size()==6){
                first_le.setVisibility(View.VISIBLE);
                second_le.setVisibility(View.VISIBLE);
                entry_1_layout.setVisibility(View.VISIBLE);
                entry_2_layout.setVisibility(View.VISIBLE);
                entry_3_layout.setVisibility(View.VISIBLE);
                entry_4_layout.setVisibility(View.VISIBLE);
                entry_5_layout.setVisibility(View.VISIBLE);
                entry_6_layout.setVisibility(View.VISIBLE);
            }
            if(item.getChannelList().size()>=1){
                title1 = item.getChannelList().get(0).getInstitutionName();
                entry_1.setText(title1);
            }
            if(item.getChannelList().size()>=2){
                title2 = item.getChannelList().get(1).getInstitutionName();
                entry_2.setText(title2);
            }
            if(item.getChannelList().size()>=3){
                title3 = item.getChannelList().get(2).getInstitutionName();
                entry_3.setText(title3);
            }
            if(item.getChannelList().size()>=4){
                title4 = item.getChannelList().get(3).getInstitutionName();
                entry_4.setText(title4);
            }
            if(item.getChannelList().size()>=5){
                title5 = item.getChannelList().get(4).getInstitutionName();
                entry_5.setText(title5);
            }
            if(item.getChannelList().size()>=6){
                title6 = item.getChannelList().get(5).getInstitutionName();
                entry_6.setText(title6);
            }
        }

    }

    @Override
    protected void initInject() {
        ButterKnife.bind(this, itemView);
    }

    @OnClick(value = {R.id.entry_1_layout, R.id.entry_2_layout, R.id.entry_3_layout, R.id.entry_4_layout, R.id.entry_5_layout, R.id.entry_6_layout})
    public void onClick(View view) {
        if (null != farmersEntryClickListener) {
            if (view.getId() == R.id.entry_1_layout) {
                farmersEntryClickListener.OnFarmersEntryClick(0);
            } else if (view.getId() == R.id.entry_2_layout) {
                farmersEntryClickListener.OnFarmersEntryClick(1);
            } else if (view.getId() == R.id.entry_3_layout) {
                farmersEntryClickListener.OnFarmersEntryClick(2);
            } else if (view.getId() == R.id.entry_4_layout) {
                farmersEntryClickListener.OnFarmersEntryClick(3);
            } else if (view.getId() == R.id.entry_5_layout) {
                farmersEntryClickListener.OnFarmersEntryClick(4);
            } else if (view.getId() == R.id.entry_6_layout) {
                farmersEntryClickListener.OnFarmersEntryClick(5);
            }
        }
    }


    public interface OnFarmersEntrysClickListener {
        void OnFarmersEntryClick(int clickPosition);
    }
}
